package com.ruoyi.wash.component;

import com.ruoyi.wash.domain.Environ;
import com.ruoyi.wash.domain.ThirdSystem;
import com.ruoyi.wash.enums.ThirdSystemInfoEnum;
import com.ruoyi.wash.service.IEnvironService;
import com.ruoyi.wash.service.IThirdSystemService;
import com.ruoyi.wash.vo.EnvironVO;
import com.ruoyi.wash.vo.ThirdSystemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: YanMing.Wang
 * @date: 2024-05-06
 * @desp: ModelMapComponent
 */
@Component
public class ModelMapComponent {


    @Autowired
    private IEnvironService iEnvironService;

    @Autowired
    private IThirdSystemService iThirdSystemService;

    /**
     * setModelMapEnvirons
     *
     * @param modelMap
     */
    public void setModelMapEnvirons(ModelMap modelMap) {
        Environ environ = new Environ();
        environ.setStatus("0");
        List<EnvironVO> environVOList = iEnvironService.selectEnvironList(environ);
        if (environVOList == null) {
            environVOList = new ArrayList<>();
        }
        modelMap.put("environVOList", environVOList);
    }

    /**
     * setModelMapEnvironSelected
     *
     * @param modelMap
     * @param environEn
     */
    public void setModelMapEnvironSelected(ModelMap modelMap, String environEn) {
        List<EnvironVO> environVOList = null;
        environVOList = (List<EnvironVO>) modelMap.get("environVOList");
        Long environId = null;
        for (EnvironVO vo : environVOList) {
            if (environEn.equals(vo.getCode())) {
                environId = vo.getId();
                break;
            }
        }
        modelMap.put("environId", environId);
    }

    /**
     * setModelMapThirdSystems
     *
     * @param modelMap
     */
    public void setModelMapThirdSystems(ModelMap modelMap) {
        ThirdSystem thirdSystem = new ThirdSystem();
        thirdSystem.setStatus("0");
        List<ThirdSystemVO> thirdSystemVOList = iThirdSystemService.selectThirdSystemList(thirdSystem);
        if (thirdSystemVOList == null) {
            thirdSystemVOList = new ArrayList<>();
        }
        modelMap.put("thirdSystemVOList", thirdSystemVOList);
    }

    /**
     * setModelMapThirdSystemSelected
     *
     * @param modelMap
     */
    public void setModelMapThirdSystemSelected(ModelMap modelMap) {
        List<ThirdSystemVO> thirdSystemVOList = null;
        thirdSystemVOList = (List<ThirdSystemVO>) modelMap.get("thirdSystemVOList");
        Long thirdId = null;
        String thirdEn = ThirdSystemInfoEnum.LIAN_TUO_FU.getCode();
        for (ThirdSystemVO vo : thirdSystemVOList) {
            if (thirdEn.equals(vo.getCode())) {
                thirdId = vo.getId();
                break;
            }
        }
        modelMap.put("thirdId", thirdId);
    }

}
